/* -----------------------------------------------------------------------------
 * PROJECT    : net.lwf
 * FILE       : fMagicAlphabetAction.java
 *
 * HISTORY:
 * Date          Author                        Description
 * ----------------------------------------------------------------------------- 
 * Jan 11, 2009       Raghu Sarraff			       Created
 */
package lwf.web.struts.action.word;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lwf.factory.WordImageFactory;
import lwf.handler.IProcessHandler;
import lwf.handler.english.WordHandler;
import lwf.handler.english.word.AlphabetDictionaryHandler;
import lwf.web.struts.action.english.WordAction;
import lwf.web.struts.action.form.english.WordDisplayActionForm;

import net.lwf.util.web.WebUtil;
import net.lwf.web.constant.IPageTitle;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;


public class AlphabetDictionaryAction extends WordAction {
	
	public ActionForward home(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		WordDisplayActionForm swform = (WordDisplayActionForm) form;
		WebUtil.removeAttribute(request, "alphabetinfo");
		WebUtil.removeAttribute(request, "alphabet");
		return super.home(mapping, form, request, response);
	} //home
	
	/**
	 * @see net.lwf.web.struts.action.english.WordAction#getHandler(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionForm)
	 */
	public WordHandler getHandler(HttpServletRequest request, ActionForm form) {
        int start = getStart(request);
        int end = getEnd(request);
        String alphabet = this.getAlphabet(request);
        List alphabetdata = (List) WebUtil.getAttribute(request, "alphabetinfo");
		return new AlphabetDictionaryHandler(start, end, alphabet, alphabetdata);
	}

	/**
	 * @see net.lwf.web.struts.action.english.WordAction#checkGrade(javax.servlet.http.HttpServletRequest, org.apache.struts.action.ActionForm)
	 */
	public void checkGrade(HttpServletRequest request, ActionForm form) {
	}

	/**
	 * @see net.lwf.web.struts.action.english.WordAction#getDisplayRows(org.apache.struts.action.ActionForm)
	 */
	public int getDisplayRows(ActionForm form) {
		return 5;
	}
	
	private String getAlphabet(HttpServletRequest request) {
		String alphabet = request.getParameter("alphabet");
		if(alphabet != null) {
			WebUtil.setAttribute(request, "alphabet", alphabet);
			Object obj = WordImageFactory.getInstance().getWordsByAlphabet(alphabet);
			WebUtil.setAttribute(request, "alphabetinfo", obj);
		}
		else {
			alphabet = (String) WebUtil.getAttribute(request, "alphabet");
		}
		return alphabet;
	}

	@Override
	public IProcessHandler getHandler(HttpServletRequest request) {
		return null;
	}
	
	@Override
	public String getPageTitle() {
		return IPageTitle.ALPHABET_DICTIONARY;
	}

	@Override
	public String getMainTitle() {
		return null;
	}

	@Override
	public String getPdfLink() {
		return null;
	}

	@Override
	public String getQuizLink() {
		return null;
	}

}

